//
//  ScrollViewStyle.swift
//  Alamofire
//
//  Created by Fanxx on 2019/7/8.
//

import UIKit

extension UCSetting where TargetType: UIScrollView {
    ///边距
    public static func inset(top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.contentInset = UIEdgeInsets(top: top, left: left, bottom: bottom, right: right)
        })
    }
    ///边距
    public static func inset(_ edgeInsets: UIEdgeInsets) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.contentInset = edgeInsets
        })
    }
    ///显示滚动条
    public static func indicator(vertical: Bool = true, horizontal: Bool = true) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.showsVerticalScrollIndicator = vertical
            target.showsHorizontalScrollIndicator = horizontal
        })
    }
    ///显示滚动条
    public static func indicator(_ shows: Bool) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.showsVerticalScrollIndicator = shows
            target.showsHorizontalScrollIndicator = shows
        })
    }
    ///翻页开关
    public static func paging(_ enabled: Bool = true) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.isPagingEnabled = enabled
        })
    }
    public static func bounce(_ bounce: Bool = true) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.bounces = bounce
        })
    }
    public static func bounce(vertical: Bool = true, horizontal: Bool = true) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.alwaysBounceVertical = vertical
            target.alwaysBounceHorizontal = horizontal
        })
    }
    ///偏移量
    public static func offset(_ contentOffset: CGPoint, animated: Bool = false) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.setContentOffset(contentOffset, animated: animated)
        })
    }
    ///偏移量
    public static func offset(x: CGFloat = 0,y:CGFloat = 0, animated: Bool = false) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.setContentOffset(CGPoint(x: x, y: y), animated: animated)
        })
    }
    ///是否可滚动
    public static func enabled(_ enabled: Bool = true) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.isScrollEnabled = enabled
        })
    }
    ///委托
    public static func delegate(_ delegate: UIScrollViewDelegate) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.delegate = delegate
        })
    }
    ///contentSize
    public static func content(_ size: CGSize) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.contentSize = size
        })
    }
    ///点击状态拦时是否自动滚到最上面
    public static func scrollsToTop(_ enable:Bool) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.scrollsToTop = enable
        })
    }
    ///contentInsetAdjustmentBehavior
    @available(iOS 11.0, *)
    public static func inset(adjust behavior:UIScrollView.ContentInsetAdjustmentBehavior) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.contentInsetAdjustmentBehavior = behavior
        })
    }
    ///automaticallyAdjustsScrollIndicatorInsets
    @available(iOS 13.0, *)
    public static func adjusts(indicator enable:Bool) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.automaticallyAdjustsScrollIndicatorInsets = enable
        })
    }
    ///isDirectionalLockEnabled
    public static func lock(direction enable:Bool) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.isDirectionalLockEnabled = enable
        })
    }
    ///indicatorStyle
    public static func indicator(style:UIScrollView.IndicatorStyle) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.indicatorStyle = style
        })
    }
    ///scrollIndicatorInsets
    public static func indicator(inset:UIEdgeInsets) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.scrollIndicatorInsets = inset
        })
    }
    ///verticalScrollIndicatorInsets
    @available(iOS 11.1, *)
    public static func verticalIndicator(inset:UIEdgeInsets) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.verticalScrollIndicatorInsets = inset
        })
    }
    ///horizontalScrollIndicatorInsets
    @available(iOS 11.1, *)
    public static func horizontalIndicator(inset:UIEdgeInsets) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.horizontalScrollIndicatorInsets = inset
        })
    }
    ///decelerationRate
    public static func deceleration(_ rate:UIScrollView.DecelerationRate) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.decelerationRate = rate
        })
    }
    ///indexDisplayMode
    public static func index(mode:UIScrollView.IndexDisplayMode) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.indexDisplayMode = mode
        })
    }
    ///delaysContentTouches
    public static func delay(touches enable:Bool) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.delaysContentTouches = enable
        })
    }
    ///canCancelContentTouches
    public static func cancelable(touches enable:Bool) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.canCancelContentTouches = enable
        })
    }
    ///bouncesZoom
    public static func zoom(bounce: Bool = true) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.bouncesZoom = bounce
        })
    }
    ///minimumZoomScale
    public static func zoom(min scale: CGFloat) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.minimumZoomScale = scale
        })
    }
    ///maximumZoomScale
    public static func zoom(max scale: CGFloat) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.maximumZoomScale = scale
        })
    }
    ///maximumZoomScale
    public static func zoom(scale: CGFloat) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.zoomScale = scale
        })
    }
    ///zoom(to rect: CGRect, animated: Bool)
    public static func zoom(to rect: CGRect, animated: Bool = false) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.zoom(to: rect, animated: animated)
        })
    }
    ///keyboardDismissMode
    public static func keyboard(dismiss mode: UIScrollView.KeyboardDismissMode) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.keyboardDismissMode = mode
        })
    }
    ///refreshControl
    public static func refresh(_ control: UIRefreshControl) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.refreshControl = control
        })
    }
}
